package com.huijutao;

import android.app.Application;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ToggleButton;

import com.huijutao.utils.ImageXutils;
import com.huijutao.utils.StringXutils;
import com.lidroid.xutils.DbUtils;
import com.lidroid.xutils.HttpUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

import cn.jpush.android.api.JPushInterface;

/**
 * 应用类，存放需要放在应用的生命周期中的全局变量、XUtils的对象（实现单例）
 * Created by 兴盛 on 2015/4/22.
 */
public class MyApp extends Application {
    public static DbUtils dbUtils;
    public static HttpUtils httpUtils;
    public static ImageXutils mImageXutils;
    public static StringXutils mStringUtils;
    private static float scale;
    private static SimpleDateFormat mSdf;

    @Override
    public void onCreate() {
        super.onCreate();
        dbUtils = DbUtils.create(this);
        httpUtils = new HttpUtils();
        mImageXutils = new ImageXutils(this);
        scale = getResources().getDisplayMetrics().density;
        mSdf = new SimpleDateFormat("yyyy-MM-dd");
        mStringUtils = new StringXutils(this);
        JPushInterface.setDebugMode(true);
        JPushInterface.init(this);
    }

    /**
     * dp转成px
     *
     * @param dipValue 想要实现的dp值
     * @return px值
     */
    public static int dip2px(int dipValue) {
        return (int) (dipValue * scale + 0.5f);
    }

    public static String formatTimeFromLong(String time) {
        return mSdf.format(new Date(Long.parseLong(time)));
    }
}
